package com.zhiwang.planet.ui.loginv2

import android.os.Bundle
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProviders
import com.zhiwang.planet.R
import com.zhiwang.planet.databinding.ActivityRegisterv2Step2Binding
import com.zhiwang.planet.mvvm.model.RestApi
import com.zhiwang.planet.mvvm.viewmodel.loginv2.FinishRegisterViewModel
import com.zhiwang.planet.ui.BaseActivity
import com.zhiwang.planet.util.Utils
import javax.inject.Inject

class RegisterV2Step2Activity :BaseActivity() {


    @Inject
    lateinit var restApi: RestApi

    lateinit var viewModel: FinishRegisterViewModel

    override fun initInjection() {
        super.initInjection()
        userComponent(this).inject(this)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val binding = DataBindingUtil.setContentView<ActivityRegisterv2Step2Binding>(
                this,
                R.layout.activity_registerv2_step2)
        Utils.setStatusBar(this, false, false)
        binding.lifecycleOwner = this
        viewModel = ViewModelProviders.of(this).get(FinishRegisterViewModel::class.java)
        binding.viewModel = viewModel

        viewModel.context = this
        viewModel.restApi = restApi
        viewModel.errorHandler = this::onError
        if (intent.hasExtra("deviceId"))
            viewModel.deviceId.value = intent.getStringExtra("deviceId")

        if(intent.hasExtra("code"))
            viewModel.imei = intent.getStringExtra("code")

    }
}